﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Application.Admin.Pic
{
    public class PicThumbSizeService : IPicThumbSizeService
    {
        Domain.Uow.IRepository<Domain.Entity.PicThumbSize> picThumbSizeRepository;

        public PicThumbSizeService(Domain.Uow.IRepository<Domain.Entity.PicThumbSize> picThumbSize)
        {
            if (picThumbSize == null)
            {
                throw new ArgumentNullException("picThumbSizeRepository is null");
            }
            picThumbSizeRepository = picThumbSize;
        }

        public Domain.Entity.PicThumbSize Add(Domain.Entity.PicThumbSize add, Domain.Entity.User operUser)
        {
            if (add == null) return add;
            picThumbSizeRepository.Add(add);
            picThumbSizeRepository.Uow.Commit();
            return add;
        }

        public bool Delete(Domain.Entity.PicThumbSize delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                delete.State = false;
                picThumbSizeRepository.Modify(delete);
                picThumbSizeRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(Domain.Entity.PicThumbSize delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                picThumbSizeRepository.Delete(delete);
                picThumbSizeRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Delete(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = picThumbSizeRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                item.State = false;
                picThumbSizeRepository.Modify(item);
            }
            try
            {
                picThumbSizeRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = picThumbSizeRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                picThumbSizeRepository.Delete(item);
            }
            try
            {
                picThumbSizeRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Modify(Domain.Entity.PicThumbSize modify, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                picThumbSizeRepository.Modify(modify);
                picThumbSizeRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public Domain.Entity.PicThumbSize Get(int id)
        {
            var data = picThumbSizeRepository.Get(id);
            return data;
        }

        public IQueryable<Domain.Entity.PicThumbSize> GetList()
        {
            var data = picThumbSizeRepository.GetList();
            return data;
        }
    }
}
